﻿@{
    ViewBag.Title = "关键词管理";
}
@section headerSection{
    <style>
        #exampleToolbar > .form-group {
            float: left;
            margin: 0;
            margin-left: 5px;
        }

        #exampleToolbar > .form-group {
            float: left;
            margin: 0;
            margin-right: 5px;
            margin-top: 1px;
        }

        .form-group > button {
            margin-top: -2px;
            margin-bottom: 2px;
        }
    </style>
}
<div class="animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins" style="margin-bottom: 0px;">
        <div class="ibox-content" style="padding: 5px 20px 0px 20px;">
            <div class="row row-lg">
                <div class="col-sm-12 col-sm-leftRight">
                    <!-- Example Toolbar -->
                    <div class="example">
                        <div class="btn-group hidden-xs" id="exampleToolbar" role="group">
                            <button id="keywordAdd" type="button" class="btn btn-outline btn-primary">
                                <i class="glyphicon glyphicon-plus" aria-hidden="true">新增</i>
                            </button>
                            <button id="keywordDel" type="button" class="btn btn-outline btn-danger">
                                <i class="glyphicon glyphicon-trash" aria-hidden="true">删除</i>
                            </button>
                            <div class="form-group" style="margin-left:0;width:160px;margin-top:-1px;">
                                <select id="vrType" name="vrType" title="请选择产品类别" data-live-search="true" class="form-control show-tick selectpicker" placeholder="请选择产品类别">
                                    <option value="-1" selected>全部</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <input id="keyword" name="keyword" type="text" class="form-control" placeholder="关键词">
                            </div>
                            <div class="form-group">
                                <button id="btnSearch" class="btn btn-primary" type="button"><i class="fa fa-search"></i>&nbsp;查询</button>
                            </div>
                        </div>
                        <table id="exampleTableToolbar" data-mobile-responsive="true" data-radio="true"></table>
                    </div>
                    <!-- End Example Toolbar -->
                </div>
            </div>
        </div>
    </div>
    <!-- End Panel Other -->
</div>
<!-- 添加/编辑 -->
<div id="boardForm" style="height:100%;overflow-x:hidden;overflow-y: auto; display: none;">
    <form class="form-horizontal m-t" id="boardFormTable" method="post" enctype="multipart/form-data">
        <div class="form-group">
            <label class="col-sm-3 control-label">产品类别<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
            <div class="col-sm-8">
                <select id="pro_type" name="pro_type" title="请选择产品类别" data-live-search="true" data-size="6" class="form-control input-sm selectpicker" placeholder="请选择产品类别">
                </select>
                <input type="hidden" id="id" name="id" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">关键词<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
            <div class="col-sm-8">
                <input id="keyword" name="keyword" type="text" class="form-control input-sm" placeholder="请输入关键词" title="请输入关键词" required="" aria-required="true" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">热度<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
            <div class="col-sm-8">
                <input id="degree" name="degree" type="text" class="form-control input-sm number" value="0" placeholder="请输入热度：整数类型" title="请输入热度：整数类型" required="" aria-required="true" />
            </div>
        </div>
    </form>
</div>
@section footSection{
    <script>
        var options, $table;
        var keywordManager = {
            initPage: function () {
                keywordManager.initSelect();
                keywordManager.initTable();
                keywordManager.bindEvent();
            },
            //初始化下拉
            initSelect: function () {
                $('#vrType').initSelectcontrol("vrProType", true);
                $('#pro_type').initSelectcontrol("vrProType");
            },
            //初始化Table
            initTable: function () {
                options = {
                    url: ctx + "/VRSearchKeyword/InitApplyTable",
                    cutHeight: 5,
                    singleSelect: false,//启用多选
                    uniqueId:"id",//唯一标记
                    toolbar: "#exampleToolbar",
                    queryParams: function (params) {
                        params = {
                            //页面大小
                            rows: params.limit,
                            //第几页
                            page: params.offset / params.limit + 1,
                            keyword: $('#keyword').val(),
                            vrType: $('#vrType').val()
                        }
                        return params;
                    },
                    columns: [
                        {
                            checkbox: true
                        }, {
                            field: '', //第一列序号
                            title: '操作',
                            align: 'center',
                            width: 50,
                            formatter: function (value, row, index) {
                                return "<button class=\"btn btn-info btn-circle btn-outline\" title='编辑' onclick=\"keywordManager.editKeyword(" + row.id + ")\" type=\"button\"><i class=\"fa fa-pencil\"></i></button>";
                            }
                        }, {
                            field: 'pro_type',
                            title: '产品类别',
                            align: 'center',
                            formatter: function (value, row, index) {
                                var proType = "";
                                switch (value) {
                                    case 1: proType = "VR作品"; break;
                                    case 2: proType = "虚仿课程"; break;
                                    case 3: proType = "头记"; break;
                                    case 4: proType = "校史馆"; break;
                                    case 5: proType = "度度圈"; break;
                                    case 6: proType = "元宇宙"; break;
                                }
                                return proType;
                            }
                        }, {
                            field: 'keyword',
                            title: '关键词',
                            align: 'center'
                        }, {
                            field: 'degree',
                            title: '热度',
                            align: 'center'
                        }, {
                            field: 'update_date',
                            title: '更新时间',
                            align: 'center'
                        }, {
                            field: 'update_name',
                            title: '更新人',
                            align: 'center'
                        }, {
                            field: 'create_date',
                            title: '创建时间',
                            align: 'center'
                        }, {
                            field: 'create_name',
                            title: '创建人',
                            align: 'center'
                        }]
                }
                $table = tableHelper.initTable("exampleTableToolbar", options);
            },
            //绑定事件
            bindEvent: function () {
                //查询
                $('#btnSearch').click(function () {
                    $table.bootstrapTable('refresh', options);
                });
                //添加
                $('#keywordAdd').on('click', function () {
                    keywordManager.editKeyword();
                });
                //删除
                $('#keywordDel').on('click', function () {
                    var row = keywordManager.selections(true);
                    if (!row || row.length<=0)
                        return false;
                    layer.confirm('您确定要删除当前选择关键词？', {
                        btn: ['确定', '取消'] //按钮
                    }, function () {
                        var index = layer.msg("删除中...", { icon: 6, time: 6000 });
                        //封装需要删除的对象
                        var ids = new Array();
                        $.each(row, function (index, item) {
                            ids.push(item.id);
                        });
                        $.ajax({
                            type: 'post',
                            url: ctx + '/VRSearchKeyword/DelKeywordById',
                            dataType: 'json',
                            data: { ids: ids.join(',') },
                            async: false,
                            success: function (data) {
                                layer.close(index);
                                if (data.Statu === 0) {
                                    layer.msg("删除成功...");
                                    $table.bootstrapTable('refresh');
                                }
                                else
                                    layer.msg(data.Msg, { icon: 5 });
                            }
                        });
                    }, function () { });
                });
            },
            resetUserType: function (userType) {
                //获取选中行数据
                var row = keywordManager.selections(true);
                if (!row)
                    return false;
                var userid = new Array();
                $.each(row, function (index, item) {
                    userid.push(item.user_id);
                });
                var index = layer.msg("VIP类别设置中...", { icon: 6, time: 6000 });
                $.ajax({
                    url: ctx + '/VRPartner/EditUserType',
                    type: "post",
                    cache: false,
                    async: false,
                    data: { "user_type": userType, "userid": userid.join(',') },
                    dataType: 'json',
                    success: function (result) {
                        if (index)
                            layer.close(index);
                        if (result.Statu === 0) {
                            layer.msg("用户类别设置成功！", { icon: 6 });
                            $table.bootstrapTable('refresh', options);
                        }
                        else
                            layer.alert(result.msg);
                    },
                    error: function () {
                        if (index)
                            layer.close(index);
                        layer.msg('数据异常~', { icon: 5 });
                    }
                });
            },
            //添加、编辑
            editKeyword: function (id) {
                var row = null;
                if (id)
                    row = $table.bootstrapTable('getRowByUniqueId', id);
                //重置界面
                var $title = "添加关键词";
                if (!row)
                    addOrEditUrl = ctx + "/VRSearchKeyword/AddKeyword";//新增
                else {
                    addOrEditUrl = ctx + "/VRSearchKeyword/EditKeyword";//编辑
                    $title = "编辑关键词";
                }
                //清空表单
                $('#boardFormTable').resetHideValidForm();
                //打开编辑
                indexForm = layer.open({
                    title: [$title, 'font-size:18px;'],
                    type: 1,
                    content: $('#boardForm'),
                    scroll: true,//是否显示滚动条、默认不显示
                    btn: ['确定', '取消'],
                    area: ['500px', '400px'],
                    success: function (li, o) {
                        if (row != null) {
                            $('#boardFormTable')[0].reset();//重置表单
                            $('#boardFormTable').LoadForm(row);//表单填充数据
                        } 
                    },
                    yes: function (li, o) {
                        if ($('#boardFormTable').valid()) {
                            //验证通过
                            $('#boardFormTable').ajaxSubmit({
                                url: addOrEditUrl,
                                type: "post",
                                dataType: "json",
                                beforeSubmit: function (arr, $form, options) {
                                    layer.msg("提交数据~", { icon: 1, time: 5000 });
                                },
                                success: function (result, status, xhr, $form) {
                                    if (result.Statu === 0) {
                                        layer.closeAll();
                                        $table.bootstrapTable('refresh');
                                        layer.msg('保存成功', { icon: 1 });
                                    }
                                    else
                                        layer.alert(result.Msg, { icon: 5 });
                                },
                                error: function (xhr, status, error, $form) {
                                    layer.msg("保存失败~", { icon: 5 });
                                }
                            });
                        }
                    },
                    cancel: function (li, o) {

                    }
                });
            },
            //获取选中行数据
            selections: function (isAll) {
                var row = $table.bootstrapTable('getSelections');
                if (!row || row.length === 0) {
                    layer.msg("数据为空或未选中记录行~", { icon: 5 });
                    return false;
                }
                if (isAll)
                    return row;
                if (row.length > 1) {
                    layer.msg("当前操作不支持多选，请选择一行再操作！", { icon: 5 });
                    return false;
                }
                return row[0];
            }
        }
        $(function () {
            keywordManager.initPage();
        });
    </script>

}